#!/usr/bin/env python
#-*-coding:utf-8-*-



class Graph(object):
    adj_factory_func = dict
    node_factory_func = dict

    def __init__(self):
        self._adj = self.adj_factory_func()
        self._nodes = self.node_factory_func()
        self.graph = {}

    def add_node(self, n, **attr):
        if n not in self._nodes:
            self._nodes[n] = attr
            self._adj[n] = self.adj_factory_func()
        else:
            self._nodes[n].update(attr)

    def add_edge(self, u, v, **attr):
        if u not in self._nodes:
            self._nodes[u] = self.node_factory_func()
            self._adj[u] = self.adj_factory_func()

        if v not in self._nodes:
            self._nodes[v] = self.node_factory_func()
            self._adj[v] = self.adj_factory_func()
        self._adj[u][v] = self.adj_factory_func()
        edge_attr = attr.copy()
        self._adj[u][v].update(edge_attr)



if __name__ == '__main__':
    G = Graph()
    dictionary = ["的确", "确实", "在理"]
    text = "他说的确实在理"
    N = len(text)
    for i in range(1, N+1):
        G.add_edge(i-1, i, weight=1, word = text[i-1])

    G.add_edge(2, 4 , weight=1, word = "的确")
    G.add_edge(3, 5, weight=1, word = "确实")
    G.add_edge(5, 7, weight=1, word = "在理")
    print(G._nodes)
    # print(G._adj)

    for k, v in G._adj.items():
        print(k, v)